Repository navigation
Compare the revalidate secret in constant time - #4882
Open
ofri-peretz wants to merge 1 commit into
Open
ofri-peretz wants to merge 1 commit into
ofri-peretz wants to merge 1 commit into
Conversation
|
@ofri-peretz is attempting to deploy a commit to the Python Italia Team on Vercel. A member of the Team first needs to authorize it. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What was wrong
frontend/src/pages/api/revalidate.tscompares the secret supplied by the caller againstprocess.env.REVALIDATE_SECRETwith!==. String comparison with!==can return early at the first differing character, so response timing can leak information about the secret.Fix
Both values are hashed with SHA-256 and compared with
crypto.timingSafeEqual. Hashing makes the buffers equal length, so a length mismatch does not throw or leak the length. A missing caller secret or an unset env var now returns the existing 401 response. No other behaviour changes. This is the pattern flagged bynode-security/no-timing-unsafe-compare.How I verified
Ran the comparison helper under Node: equal secret returns true; different secret, shorter secret, undefined input and unset env var all return false. The edited file parses cleanly with Node's TypeScript stripping. I did not run the full app or test suite.
AI disclosure: drafted with AI assistance (Claude); I reviewed and tested the change.